package testadvance;

import oop2.Cat;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class SetTest {
    public static void main(String[] args) {
        //无序，不允许重复
        Set<String> set=new HashSet<>();
        set.add("猫");
        set.add("猫");
        set.add("狗");
        set.add("狗");
        set.add("狗");
        set.add("牛");
        set.add("兔子");
        System.out.println(set.size());
        System.out.println(set);
        for(String s:set)
            System.out.println(s);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>");
        //迭代器：
        Iterator<String> it = set.iterator();
        while(it.hasNext()){
            String v=it.next();
            System.out.print(v+"   ");
        }
        System.out.println();
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>");
        Set<Cat> s2=new HashSet<>();
        s2.add(new Cat("小花花","短耳帽"));
        s2.add(new Cat("大花花","长耳猫"));
        s2.add(new Cat("大花花","田园猫"));
        s2.add(new Cat("大花花","黑猫"));
        System.out.println(s2.size());//2
        System.out.println(s2);
        for(Cat c:s2)
            c.show();
    }
}
